
#ifndef __VTY_PROXY_AGENT_SESSION_HPP__
#define __VTY_PROXY_AGENT_SESSION_HPP__ 

#include "khan.hpp"
#include "vty.hpp"
#include "vty_ipc_msg.hpp"

class vty_agent_session
:public vty,
public boost::enable_shared_from_this<vty_agent_session>,
private boost::noncopyable       
{
public:
    explicit vty_agent_session(io_service& ioserv);
    ~vty_agent_session();

    int id() { return _id; }
    void start() { run(); }
    void stop() { _socket.close(); }
    tcp_socket& socket() { return _socket; }

    bool is_auth_mode();
    bool is_auth_mode(const std::string& mode);

    bool check_passwd(const std::string passwd);

    bool change_mode(const std::string& mode);
    const std::string current_mode();

    int output(const char c);
    int output(const std::string& string);
    int output(const char* fmt, ...);

    bool is_dialog();
    int stop_dialog();
    int start_dialog(DialogHandle hdnl);

    /* FIXME: REMOVE */
    const std::string prompt() { std::string tmp; return tmp; };
    const std::string get_banner() { return prompt(); } 
    void set_banner(const std::string& banner) {}
    void excute_pty(const string_vector& cmdvec) {}
    void set_func_flag(bool flag) { }
    bool get_func_flag() { return true; };
    bool is_stop() { return false; };
    void excute_command(const std::string commandline) {};
    void describe_command(const std::string commandline) {};
    void complete_command(const std::string commandline) {};


    void run();
    
private:
    int handle_diag_function(string_vector& opts);
    bool handle_vty_mesage(vty_ipc_message_t& msg);
    int start_function(int vty_id, string_vector& opts);

    __u32 send_vty_msg(__u32 vty_id, __u32 cmd, 
            string_vector& req_opts, string_vector& resp_opts);

    bool send_ipc(vty_ipc_message_t& msg);
    bool recv_ipc(vty_ipc_message_t& msg);
    
    int _id;
    tcp_socket  _socket;
    vty_ipc_msg _ipcmsg;
    vty_ipc_message_t _recv_msg;
    bool    _is_dialog;
    DialogHandle    _diag_function;
};


typedef boost::shared_ptr<vty_agent_session> vty_agent_session_ptr;

#endif /* __VTY_PROXY_AGENT_SESSION_HPP__ */
